package gdconf

import (
	"server_cluster/common/logger"
)

// 鱼饵配置表

type FishBaitConfig struct {
	FishBaitId int32    `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 鱼饵id
	Effect     IntArray `csv:"Func,omitempty"`                            // 加成效果
}

func (f *FishBaitConfig) TableName() string {
	return "config_fish_bait"
}

func (g *GameDataConfig) saveFishBaitConfig() {
	saveTableToDb[FishBaitConfig](g.Db, readTable[FishBaitConfig](g.CsvPathPrefix+"FishingBait.csv"))
}

func (g *GameDataConfig) loadFishBaitConfig() {
	g.GameDataMaps.FishBaitConfigMap = make(map[int32]*FishBaitConfig)
	for _, fishBaitConfig := range loadTableFromDb[FishBaitConfig](g.Db) {
		g.GameDataMaps.FishBaitConfigMap[fishBaitConfig.FishBaitId] = fishBaitConfig
	}
	logger.Info("FishBaitConfig Count: %v", len(g.GameDataMaps.FishBaitConfigMap))
}

func GetFishBaitConfig(fishBaitId int32) *FishBaitConfig {
	value, exist := CONF.GameDataMaps.FishBaitConfigMap[fishBaitId]
	if !exist {
		logger.Error("[ConfigNotFound] FishBaitConfig, fishBaitId: %v", fishBaitId)
		return nil
	}
	return value
}

func GetFishBaitConfigMap() map[int32]*FishBaitConfig {
	return CONF.GameDataMaps.FishBaitConfigMap
}
